﻿using System;
using System.Web.WebPages.Html;

namespace Shinkansen.Mvc
{
    public static class ImageExtensions
    {
        /// <summary>
        /// An image extension for MVC.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="path">The URL.</param>
        /// <param name="alternateText">The alternate text.</param>
        /// <returns></returns>
        public static string Image (this HtmlHelper helper, string path, string alternateText)
        {
            return Image (helper, path, alternateText, null);
        }

        /// <summary>
        /// An image extension for MVC.
        /// </summary>
        /// <param name="helper">The helper.</param>
        /// <param name="path">The URL.</param>
        /// <param name="alternateText">The alternate text.</param>
        /// <param name="htmlAttributes">The HTML attributes.</param>
        /// <returns></returns>
        public static string Image (this HtmlHelper helper, string path, string alternateText, object htmlAttributes)
        {
            string           imageTag = null;
            ImageReference   image = new ImageReference (path, alternateText, htmlAttributes);
            Action<string>   buildImageTag = tag => imageTag = tag;

            new ImageTagBuilder (image, buildImageTag).Run ();
            return imageTag;
        }
    }
}